/**
 * 这一课和是上一课的进阶版  用工厂的概念 实现了更强大的自定义功能
 */

{
	const ErrorDecoratorFactor = (
		title: string = 'Jimmy will still love Xuexue'
	): MethodDecorator => {
		return (
			target: Object,
			propertyKey: string | symbol,
			descriptor: PropertyDescriptor
		) => {
			let method = descriptor.value
			descriptor.value = () => {
				try {
					method()
				} catch (error: any) {
					console.log(`%c${title}`, 'color:#e67e22;font-size:30px')
					console.log(`%c${error.message}`, 'color:red;font-size:16px')
				}
			}
		}
	}

	class User {
		@ErrorDecoratorFactor('hello world 自定义错误工厂')
		public find() {
			throw new Error('查找用户失败')
		}
	}

	new User().find()
}
